#include <Common/CountDownLatch.h>
#include <Common/ThreadPool2.h>
#include <stdio.h>
#include <unistd.h>

void test_func(void *arg)
{
	Int32 *p = (Int32*)arg;

	sleep(1);

	printf("test_func %d\n", *p);
	delete p;
}

int main()
{
    CThreadPool2 pool;
	pool.SetMaxQueueSize(10);
	pool.Start(5, 31);

	for (int i = 0; i < 100; ++i)
	{
		Int32 *pSeq = new Int32(i);
		pool.Run(test_func, (void*)pSeq);
	}

	CCountDownLatch latch(1);
	pool.Run(CCountDownLatch::CountDown_, (void*)&latch);
	latch.Wait();

	pool.Stop();
    return 0;
}

